---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(flexdashboard)
```
Column {data-width=300}
-----------------------------------------------------------------------
### Number of items ordered in each department
```{r}
data("instacart")
instacart %>%
count(department) %>%
mutate(
department = factor(department),
department = fct_reorder(department, n)
) %>%
plot_ly(
x = ~department, y = ~n,
alpha = .5, type = "scatter", mode = "markers") %>%
layout(yaxis = list(title = "number of items ordered"))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Number of items ordered in beverage and snacks aisle
```{r}
aisle_df =
instacart %>%
group_by(department) %>%
count(aisle) %>%
filter(department == "beverages" | department == "snacks") %>%
mutate(
aisle = factor(aisle),
aisle = fct_reorder(aisle, n)
)
aisle_df %>%
mutate(text_label = str_c("Department: ", department)) %>%
plot_ly(
x = ~aisle, y = ~n, color = ~department, text = ~text_label,
alpha = .5, type = "bar", colors = "viridis") %>%
layout(yaxis = list(title = "number of items ordered"))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Number of orders placed in each hour on weekends
```{r}
dow_df =
instacart %>%
filter(order_dow == '0' | order_dow == '1' | order_dow == '6') %>%
mutate(
order_dow = recode(order_dow,
"0" = "Saturday",
"1" = "Sunday",
"6" = "Friday"),
order_dow = factor(order_dow)) %>%
group_by(order_dow, order_hour_of_day) %>%
count(order_hour_of_day)
dow_df %>%
ungroup() %>%
plot_ly(
x = ~order_hour_of_day, y = ~n, color = ~order_dow,
type = "scatter", mode = "lines+markers", colors = "viridis") %>%
layout(
xaxis = list(title = "hour of the day"),
yaxis = list(title = "number of items ordered"))
```